package adc.app.ui.wicket.table;

import org.apache.wicket.Component;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.ComponentModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public class RowNumColumn<T> extends AbstractColumn<T> {
	private static final long serialVersionUID = 1L;

	public RowNumColumn(IModel<String> displayModel) {
		super(displayModel);
	}
	
	public RowNumColumn() {
		super(new Model<String>());
	}

	@Override
	public void populateItem(Item<ICellPopulator<T>> cellItem,
			String componentId, IModel<T> rowModel) {
		cellItem.add(new Label(componentId, new RowNumModel()));
	}
	
	private static final class RowNumModel extends ComponentModel<Integer> {

		private static final long serialVersionUID = 1L;

		@Override
		protected Integer getObject(Component component) {
			Item<?> item = (Item<?>) component.getParent();
			return item.getIndex();
		}
		
	}
	
	

	@Override
	public final boolean isSortable() {
		return false;
	}
	
	

}
